package cn.arnold.offer.bytedance;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String text1 = scanner.nextLine();
        String text2 = scanner.nextLine();
        System.out.println(solution(text1, text2));
    }

    static int solution(String text1, String text2) {
        if (text1.isEmpty() || text2.isEmpty()) {
            return 0;
        }
       /* int m = text1.length();
        int n = text2.length();
        int[][] dp = new int[m + 1][n + 1];
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                char c1 = text1.charAt(i);
                char c2 = text2.charAt(j);
                if (c1 == c2) {
                    dp[i + 1][j + 1] = dp[i][j] + 1;
                } else {
                    dp[i + 1][j + 1] = Math.max(dp[i + 1][j], dp[i][j + 1]);
                }
            }
        }
        return dp[m][n];*/
        int count = 0;
        for (int i = 0; i < text2.length(); i++) {
            char c = text2.charAt(i);
            int flag = text1.indexOf(c, 0);
            if (flag == -1) {
                continue;
            } else {
                count++;
                text1 = del(text1, flag);
            }
        }
        return count;
    }

    static String del(String s, int index) {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < s.length(); i++) {
            if (i != index) {
                sb.append(s.charAt(i));
            }
        }
        return sb.toString();
    }
}
